import { onReady } from '@dcloudio/uni-app'

export function useShare(
  onShareAppMessage:
    | ((
        options: Page.ShareAppMessageOption
      ) => Page.CustomShareContent | Promise<Omit<Page.CustomShareContent, 'promise'>>)
    | undefined
) {
  onReady(() => {
    const currentPage = getCurrentPages().pop()
    if (currentPage) {
      currentPage.onShareAppMessage = onShareAppMessage
    }
  })
}
